/*
 * SpecialEffect.java
 *
 * Created on 12 November 2006, 11:59
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package digitrix.fightclub.game;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author Josh
 */
public class SpecialEffect extends Sprite {
       
    public final static int SPECIAL_EFFECT_HIGH_FIRE_KICK   = 0; 
    public final static int SPECIAL_EFFECT_LOW_FIRE_KICK    = 1;
    private final static int SPECIAL_EFFECT_COUNT = 2; 
    
    private final static int SPECIAL_EFFECT_WIDTH = 20;
    private final static int SPECIAL_EFFECT_HEIGHT = 20; 
        
    private int _frameTime;
    private int _displayTime;
    private int _type;
    // attributes of a specific type
    private static int[][] _frameSequences; // animation sequence for the special effects
    
    
    /** Creates a new instance of SpecialEffect */
    public SpecialEffect( Image image ) {
        super( image, SPECIAL_EFFECT_WIDTH, SPECIAL_EFFECT_HEIGHT ); 
        
        defineReferencePixel( this.getWidth()/2, this.getHeight()/2 );
        setVisible(false);
        
        initAnimations(); 
        
        _type = -1;
    }
    
    public void init( int type, int startingX, int startingY, boolean isFacingLeft ){
        // make sure a valid type has been passed through        
        if( type < 0 || type > SPECIAL_EFFECT_COUNT )
            return;
        
        setPosition( startingX, startingY );
        _frameTime = 0;
        _displayTime = 0;
        _type = type;
        setVisible(true);
        
        // assign the right frame sequence to the type of effect requested      
        setFrameSequence( _frameSequences[_type] );
        setFrame( 0 );
        
        if( !isFacingLeft )
            setTransform( TRANS_MIRROR );                 
    }
    
    public void tick( long elapsedTime ){
        _displayTime += elapsedTime;
        
        switch( _type ){
            case SPECIAL_EFFECT_HIGH_FIRE_KICK:
                if( _displayTime > 200 )
                    setVisible( false ); 
                break; 
            case SPECIAL_EFFECT_LOW_FIRE_KICK:
                if( _displayTime > 200 )
                    setVisible( false ); 
                break; 
        }
    }
    
    public boolean isFree(){
        return !isVisible();
    }
    
    private void initAnimations(){
        if( _frameSequences != null )
                return;
            
            _frameSequences = new int[SPECIAL_EFFECT_COUNT][];            
            
            int highKickFire[] = {0};
                        
            _frameSequences[SPECIAL_EFFECT_HIGH_FIRE_KICK] = highKickFire;
    }        
    
}
